import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'calculatePrice',
})
export class CalculatePricePipe implements PipeTransform {
  transform(value: any, args?: any): any {
    if (!args) {
      args = 1;
    }
    let result = null;
    const v = value * args + '';
    const tv: string = Math.round(parseFloat(v) * 100) / 100 + '';
    const arr = tv.split('.');
    if (arr.length === 1) {
      result = tv + '.00';
    } else if (arr.length > 1 && arr[1].length < 2) {
      result = tv + '0';
    } else {
      result = tv;
    }
    return result;
  }
}
